package com.jbit.hxy.controller;

import com.jbit.hxy.common.Result;
import com.jbit.hxy.model.dto.DishFromDTO;
import com.jbit.hxy.model.dto.DishQueryDTO;
import com.jbit.hxy.model.po.WxDish;
import com.jbit.hxy.service.menu.CategoryDishService;
import com.jbit.hxy.service.menu.WxDishService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dish")
@RequiredArgsConstructor
@Tag(name = "菜品管理", description = "提供菜品相关的 API 接口")
public class WxDishController {
    private final WxDishService wxDishService;
    private final CategoryDishService categoryDishService;
    @PostMapping("/list")
    @Operation(summary = "查询菜品列表",description = "根据条件查询菜品列表")
    public Result list(@RequestBody DishQueryDTO dishQueryDTO){
        return wxDishService.getDishes(dishQueryDTO);

    }
    @PostMapping("/add")
    @Operation(summary = "添加菜品",description = "添加菜品")
    public Result addDishes(@RequestBody DishFromDTO dishFromDTO){
        return wxDishService.addDishes(dishFromDTO);
    }
    @PostMapping("/update")
    @Operation(summary = "修改菜品",description = "修改菜品")
    public Result updateDishes(@RequestBody DishFromDTO dishFromDTO){
        return wxDishService.updateDishes(dishFromDTO);
    }
    @GetMapping("/delete")
    @Operation(summary = "删除菜品",description = "删除菜品")
    public Result deleteDishes(@RequestParam("id") Integer id){
        return wxDishService.deleteDishes(id);
    }

    @GetMapping("/getDishBycateId")
    @Operation(summary = "根据分类id查询菜品",description = "根据分类id查询菜品")
    public Result getDishBycateId(@RequestParam("cateId") Integer cateId){
        return wxDishService.getDishBycateId(cateId);
    }
    @GetMapping("/getDishIdsBycateId")
    @Operation(summary = "根据分类id查询菜品id",description = "根据分类id查询菜品id")
    public Result getDishIdsBycateId(@RequestParam("cateId") Integer cateId){
        return categoryDishService.getDishIdsBycateId(cateId);
    }

    @GetMapping("/getDishes")
    @Operation(summary = "查询所有菜品",description = "查询所有菜品")
    public Result getDishes(){
        return wxDishService.getAllDishes();
    }


    @GetMapping("/getDishDetail")
    @Operation(summary = "查询菜品详情",description = "查询菜品详情")
    public Result getDishDetail(@RequestParam("id") Integer id){
        return wxDishService.getDishDetail(id);
    }

    @GetMapping("/getDishById")
    @Operation(summary = "根据id查询菜品",description = "根据id查询菜品")
    public Result<WxDish> getDishById(@RequestParam("id") Long dishId){
        WxDish wxDish = wxDishService.getById(dishId);
        return Result.success(wxDish);
    }

    @GetMapping("/getDishNameById")
    @Operation(summary = "根据id查询菜品名称",description = "根据id查询菜品名称")
    public Result getDishNameById(@RequestParam("id") Integer dishId){
        return wxDishService.getDishNameById(dishId);
    }

}
